home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / dev / basic / BlitzLstApr02.lha / BlitzLstApr02 / attachments / mail_42 / own2.lha / OwnLib.BB2 < prev    next >
Text File  |  2000-02-16  |  8KB  |  220 lines

  1.  
  2. #VERSION = 1
  3. #REVISION = 4
  4.  
  5. #_LVOFreeMem = -210
  6. #_LVORemove  = -252
  7.  
  8. XINCLUDE "ownlib_i.bb2" ; the library base definition
  9.  
  10. ; You could use all the separate includes, or you can just stick
  11. ; amigalibs.res as a resident
  12.  
  13. ; some things that are in the ASM includes, but not C includes,
  14. ; and so are not in the amigalibs.res file
  15.  
  16. #RTC_MATCHWORD  = $4AFC
  17.  
  18. #RTB_AUTOINIT   = 7
  19. #RTF_AUTOINIT   = (1 LSL #RTB_AUTOINIT)
  20.  
  21. #LIBB_SUMMING   = 0
  22. #LIBB_CHANGED   = 1
  23. #LIBB_SUMUSED   = 2
  24. #LIBB_DELEXP    = 3
  25. #LIBB_EXP0CNT   = 4
  26.  
  27. #LIBF_SUMMING   = (1 LSL #LIBB_SUMMING)
  28. #LIBF_CHANGED   = (1 LSL #LIBB_CHANGED)
  29. #LIBF_SUMUSED   = (1 LSL #LIBB_SUMUSED)
  30. #LIBF_DELEXP    = (1 LSL #LIBB_DELEXP)
  31. #LIBF_EXP0CNT   = (1 LSL #LIBB_EXP0CNT)
  32.  
  33. ; !INITBYTE{offset,value}
  34. Macro INITBYTE
  35.     CNIF `1<=255
  36.     Dc.b    $A0,`1
  37.     Dc.b    `2,0
  38.     CELSE
  39.     Dc.b    $E0,0
  40.     Dc.w    `1
  41.     Dc.b    `2,0
  42.     CEND
  43. End Macro
  44.  
  45. ; !INITWORD{offset, value}
  46. Macro INITWORD
  47.     CNIF `1<=255
  48.     Dc.b    $90,`1
  49.     Dc.w    `2
  50.     CELSE
  51.     Dc.b    $D0,0
  52.     Dc.w    `1
  53.     Dc.w    `2
  54.     CEND
  55. End Macro
  56.  
  57. ; !INITLONG{offset,value}
  58. Macro INITLONG
  59.     CNIF `1<=255
  60.     Dc.b    $80,`1
  61.     Dc.l    `2
  62.     CELSE
  63.     Dc.b    $C0,0
  64.     Dc.w    `1
  65.     Dc.l    `2
  66.     CEND
  67. End Macro
  68.  
  69. ; Don't know how to do INITSTRUCT properly because it contains
  70. ; labels within the macro. These have got to be unique. Could
  71. ; do it by sticking a global label at the top of the macro and then
  72. ; using local labels, but still don't know how to get the global
  73. ; label unique :((
  74.  
  75. ;size=source size 0=long, 1=word, 2=byte, 3=illegal.
  76. ;offset=offset from memory base to put data
  77. ;value=unused
  78. ;count=number of source items to copy, minus one
  79. ;follow this macro with the proper sized data (dc.b,dc.w,dc.l,etc.)
  80. ;INITSTRUCT MACRO   ; &size,&offset,&value,&count
  81. ;       DS.W    0
  82. ;       IFC '\4',''
  83. ;COUNT\@    SET 0
  84. ;       ENDC
  85. ;       IFNC    '\4',''
  86. ;COUNT\@    SET \4
  87. ;       ENDC
  88. ;CMD\@      SET (((\1)<<4)!COUNT\@)
  89. ;       IFLE    (\2)-255    ;byte offset large enough?
  90. ;       DC.B    (CMD\@)!$80
  91. ;       DC.B    \2
  92. ;       MEXIT
  93. ;       ENDC
  94. ;       DC.B    CMD\@!$0C0  ;byte too small, use 24-bit offset.
  95. ;       DC.B    (((\2)>>16)&$0FF)
  96. ;       DC.W    ((\2)&$0FFFF)
  97. ;       ENDM
  98.  
  99.  
  100. begin:  MOVEQ.l #-1,d0
  101.         RTS
  102.  
  103. ; RTC_MATCHWORD indicates where RomTag-structure begins.
  104. ; Next there is poiter to the structure itself. This is meant to prevent
  105. ; interpreting any code as RomTag by mistake.
  106.  
  107. ; RTF_AUTOINIT flag will make the Exec to do the initialization of jump tables for this library
  108. ; according to the tables below. (InitStuff)
  109.  
  110.  
  111.  
  112. ROMTag:   Dc.w  #RTC_MATCHWORD  ; UWORD RT_MATCHWORD
  113.           Dc.l  ROMTag          ; APTR  RT_MATCHTAG
  114.           Dc.l  EndOfLib        ; APTR  RT_ENDSKIP
  115.           Dc.b  #RTF_AUTOINIT   ; UBYTE RT_FLAGS
  116.           Dc.b  #VERSION        ; UBYTE RT_VERSION
  117.           Dc.b  #NT_LIBRARY     ; UBYTE RT_TYPE
  118.           Dc.b  0               ; BYTE  RT_PRI
  119.           Dc.l  LibName         ; APTR  RT_NAME
  120.           Dc.l  LibId           ; APTR  RT_IDSTRING
  121.           Dc.l  InitStuff       ; APTR  RT_INIT
  122.  
  123. LibName:  !LIBRARYNAME
  124. LibId:    Dc.b  "own.library 1.6 (16/02/2000)",0
  125.           Even  ; was ds.w 0 - you can use Even with ASM only progs, seems to work OK
  126.  
  127. InitStuff:Dc.l  SizeOf.LibraryBase  ; Structure size
  128.           Dc.l  Functions           ; Jump table address
  129.           Dc.l  LibBaseData         ; Information for the initialization
  130.           Dc.l  InitRoutine         ; Own initialization routine
  131.  
  132. Functions:Dc.l  r_Open      ; Open routine address
  133.           Dc.l  r_Close     ; Close routine address
  134.           Dc.l  r_Expunge   ; Expunge routine address
  135.           Dc.l  r_Null      ; ** Reserved **
  136.           Dc.l  r_First     ; First user routine address
  137.           Dc.l  -1          ; Table ends
  138.  
  139. LibBaseData:!INITBYTE{SizeOf.Node\ln_Type,#NT_LIBRARY}
  140.             !INITLONG{SizeOf.Node\ln_Name,LibName}
  141.             !INITBYTE{SizeOf.Library\lib_Flags,#LIBF_SUMUSED|LIBF_CHANGED}
  142.             !INITWORD{SizeOf.Library\lib_Version,#VERSION}
  143.             !INITWORD{SizeOf.Library\lib_Revision,#REVISION}
  144.             !INITLONG{SizeOf.Library\lib_IdString,LibId}
  145.             Dc.l        0
  146.  
  147.  
  148. InitRoutine:  MOVE.l  a5,-(a7)                                          ; Save A5
  149.               MOVE.l  d0,a5                                             ; Library Base address
  150.               MOVE.l  a6,SizeOf.LibraryBase\libb_SysLib(a5)             ; Store ExecBase to library data
  151.               MOVE.l  a0,SizeOf.LibraryBase\libb_SegList(a5)            ; Store SegList to library d ta
  152.  
  153.               ; If any other initialization operations are required put them here
  154.  
  155.               MOVE.l  a5,d0                                             ; Return the Base addres in  0
  156.               MOVE.l  (a7)+,a5                                          ; Restore A5
  157.               RTS
  158.  
  159. .r_Open:      ADDQ.w  #1,SizeOf.Library\lib_OpenCnt(a6)                 ; New user for this library so increase ope count
  160.               BCLR    #LIBB_DELEXP,SizeOf.LibraryBase\libb_Flags(a6)    ; ...Expunge is forbid
  161.               MOVE.l  a6,d0                                             ; Return BASE address in D0
  162.               RTS
  163.  
  164. .r_Close:     MOVEQ   #0,d0                                             ; Return value
  165.               SUBQ.w  #1,SizeOf.Library\lib_OpenCnt(a6)                 ; Decrease open count
  166.               BNE     'nousers                                          ; Is there any users?
  167.               BTST    #LIBB_DELEXP,SizeOf.LibraryBase\libb_Flags(a6)    ; No, so we test if there are delayed Expunge request?
  168.               BEQ     'nousers
  169.               BSR     r_Expunge                                         ; Yes! so we jump to expunge
  170. 'nousers:     RTS                                                       ; Return where ever we were called from.
  171.  
  172. .r_Expunge:   MOVEM.l d2/a5-a6,-(a7)                                    ; Save registers
  173.               MOVE.l  a6,a5                                             ; Library base address
  174.               MOVE.l  SizeOf.LibraryBase\libb_SysLib(a5),a6             ; ExecBase
  175.               TST.w   SizeOf.Library\lib_OpenCnt(a5)                    ; Library still having users?
  176.               BEQ     'nousers
  177.               BSET    #LIBB_DELEXP,SizeOf.LibraryBase\libb_Flags(a5)    ; Yes! -> Delayed expunge
  178.               MOVEQ   #0,d0                                             ; We ret rn NULL
  179.               MOVEM.l (a7)+,d2/a5-a6
  180.               RTS
  181.  
  182. 'nousers:     MOVE.l  SizeOf.LibraryBase\libb_SegList(a5),d2            ; Save SegList-address to D2
  183.               MOVE.l  a5,a1
  184. ;              xref    _LVORemove                                       ; And we remove the library...
  185.               JSR     _LVORemove(a6)                                    ; ... from the system list
  186.  
  187.               ; Any other clean up's needed? If so then do those here
  188.  
  189.               MOVEQ   #0,d0                                             ; clear D0
  190.               MOVE.l  a5,a1                                             ; Library base
  191.               MOVE.w  SizeOf.Library\lib_NegSize(a5),d0                 ; Library negative size
  192.               SUB.l   d0,a1                                             ; Points at the start of memory block
  193.               ADD.w   SizeOf.Library\lib_PosSize(a5),d0                 ; Add library positive size
  194. ;              xref     _LVOFreeMem                                     ;  nd we...
  195.               JSR     _LVOFreeMem(a6)                                   ; ... free the memory
  196.               MOVE.l  d2,d0                                             ; Restore SegList
  197.               MOVEM.l (a7)+,d2/a5-a6
  198.               RTS
  199.  
  200. .r_Null:      MOVEQ #0,d0                                               ; Reserved routine HAVE TO RETURN NULL IN D0
  201.               RTS
  202.  
  203. ;******* Here are the user library routines *******
  204.  
  205. .r_First:
  206. ;   movem.l d2-d4/a2,-(sp)  ; Save any Data/Address registers exept d0,d1,a0,a1
  207.                             ; which can be altered freely
  208. ; Your routine code goes here
  209. ;   ** Example code **
  210.  
  211.     ADD.l d1,d0
  212.  
  213. ;   movem.l (sp)+,d2-d4/a2  ; Restore the saved registers
  214.     RTS
  215.  
  216. ;**************************************************
  217.  
  218. EndOfLib:     Even
  219.  
  220.